// 封装的节流函数
export default function throttle(fn, interval = 200) {
  let last = null;
  let timer= null;
  return function () {
    const th = this;
    const args = arguments;
    const now = +new Date();

    if (last && now - last < interval) {
      clearTimeout(timer);
      timer = setTimeout(function () {
        last = now;
        fn.apply(th, args);
      }, interval);
    } else {
      last = now;
      fn.apply(th, args);
    }
  }
}